package com.ptu.service.impl;

import com.ptu.entity.PageTools;
import com.ptu.entity.Payment;
import com.ptu.service.PaymentService;
import com.ptu.util.DBUtil;
import com.ptu.mapper.PaymentMapper;

import java.sql.Date;
import java.util.List;

public class PaymentServiceImpl implements PaymentService {

    @Override
    public List<Payment> findPayMore(String paytime, String payempid, String paytype) {
        PaymentMapper mapper = DBUtil.getSqlSession().getMapper(PaymentMapper.class);
        List<Payment> payments = mapper.selectPayMore(paytime, payempid, paytype);
        DBUtil.closeAll();
        return payments;
    }

    @Override
    public PageTools<Payment> findPayAll(int pageSize, int pageNumber) {
        PaymentMapper mapper = DBUtil.getSqlSession().getMapper(PaymentMapper.class);

        PageTools<Payment> pageTools = new PageTools<>();
        pageTools.setPageNumber(pageNumber);
        pageTools.setPageSize(pageSize);

        int pageStart = pageSize*(pageNumber-1);
        List<Payment> employees = mapper.selectPage(pageSize, pageStart);
        int total = mapper.selectPayCount();
        pageTools.setTotal(total);
        pageTools.setList(employees);

        DBUtil.closeAll();
        return pageTools;
    }

    @Override
    public List<Payment> findAll() {
        PaymentMapper mapper = DBUtil.getSqlSession().getMapper(PaymentMapper.class);
        List<Payment> pay = mapper.selectAll();
        DBUtil.closeAll();
        return pay;
    }

    @Override
    public int addpayment(Payment pay) {
        PaymentMapper mapper = DBUtil.getSqlSession().getMapper(PaymentMapper.class);
        int insertpayment = mapper.insertpayment(pay);
        DBUtil.closeAll();
        return insertpayment;
    }

    @Override
    public int removepay(Integer pid) {
        PaymentMapper mapper = DBUtil.getSqlSession().getMapper(PaymentMapper.class);
        int i = mapper.delectpay(pid);
        DBUtil.closeAll();
        return i;
    }

    @Override
    public int changepay(Payment pay) {
        PaymentMapper mapper = DBUtil.getSqlSession().getMapper(PaymentMapper.class);
        int updatepay = mapper.updatepay(pay);
        DBUtil.closeAll();
        return updatepay;
    }

    @Override
    public Payment findPayByPid(Integer pid) {
        PaymentMapper mapper = DBUtil.getSqlSession().getMapper(PaymentMapper.class);
        Payment pay = mapper.selectPayByPid(pid);
        DBUtil.closeAll();
        return pay;
    }

    @Override
    public int selectXMKFCountService(){
        PaymentMapper mapper = DBUtil.getSqlSession().getMapper(PaymentMapper.class);
        int totalXMKFCount = mapper.selectXMKFCount();
        DBUtil.closeAll();
        return totalXMKFCount;
    }

    @Override
    public int selectStuCountService(){
        PaymentMapper mapper = DBUtil.getSqlSession().getMapper(PaymentMapper.class);
        int totalStuCount = mapper.selectStuCount();
        DBUtil.closeAll();
        return totalStuCount;
    }

    @Override
    public int selectRYWBCountService(){
        PaymentMapper mapper = DBUtil.getSqlSession().getMapper(PaymentMapper.class);
        int totalRYWBCount = mapper.selectRYWBCount();
        DBUtil.closeAll();
        return totalRYWBCount;
    }

    @Override
    public int selectBMCountService(){
        PaymentMapper mapper = DBUtil.getSqlSession().getMapper(PaymentMapper.class);
        int totalBMCount = mapper.selectBMCount();
        DBUtil.closeAll();
        return totalBMCount;
    }

    @Override
    public int selectXMKFPayService() {
        PaymentMapper mapper = DBUtil.getSqlSession().getMapper(PaymentMapper.class);
        int totalXMKFPay = mapper.selectXMKFPay();
        DBUtil.closeAll();
        return totalXMKFPay;
    }

    @Override
    public int selectStuPayService() {
        PaymentMapper mapper = DBUtil.getSqlSession().getMapper(PaymentMapper.class);
        int totalStuPay = mapper.selectStuPay();
        DBUtil.closeAll();
        return totalStuPay;
    }

    @Override
    public int selectRYWBPayService() {
        PaymentMapper mapper = DBUtil.getSqlSession().getMapper(PaymentMapper.class);
        int totalRYWBPay = mapper.selectRYWBPay();
        DBUtil.closeAll();
        return totalRYWBPay;
    }

    @Override
    public int selectBMPayService() {
        PaymentMapper mapper = DBUtil.getSqlSession().getMapper(PaymentMapper.class);
        int totalBMPay = mapper.selectBMPay();
        DBUtil.closeAll();
        return totalBMPay;
    }

}
